﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="TSV.Areas.Administration.Models" %>
<script type="text/javascript" src="/Scripts/highslide/highslide.js"></script>
<link rel="stylesheet" type="text/css" href="/Scripts/highslide/highslide.css" />
<script src="/Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
<%
    CategoryDao catDao = new CategoryDao();
    DistrictDao distDao = new DistrictDao();
    ProvinceDao proDao = new ProvinceDao();
    Partner partner = (Partner)ViewData.Model;    
%>
<script type="text/javascript">
    hs.graphicsDir = '/Scripts/highslide/graphics/';
    hs.outlineType = 'rounded-white';
</script>
<script type="text/javascript">
    $(document).ready(function () {
        CKEDITOR.replace('Description', {
            filebrowserImageUploadUrl: '/Administration/Common/UploadImage',
            filebrowserFlashUploadUrl: '/Administration/Common/UploadFlash',
            entities: false
        });
        $("#PartnerForm").validate({
            debug: false,
            errorElement: "span",
            errorPlacement: function (error, element) {
                error.tooltip({
                    bodyHandler: function () {
                        return error.html();
                    }
                });
                error.insertAfter(element);
            },
            rules: {
                PartnerName: {
                    required: true
                },
                CategoryID: {
                    required: true
                },
                Street1: {
                    required: true
                },
                District1: {
                    required: true
                },
                Province1: {
                    required: true
                },
                Status: {
                    required: true
                },
                ReceivedTime: {
                    required: true
                },
                Email: {
                    email: true
                },
                ExpireDate: {
                    required: true,
                    checkDate: true
                },
                OldPrice: {
                    number: true
                },
                CurrentPrice: {
                    number: true
                }
            }
        });
        $("#btnChangePhoto").click(function () {
            var url = "/Administration/Common/UploadImage?controller=<%=Constants.PARTNER_DEFAULT_VALUE %>&recordID=" + $('#RecordID').val() + "&saveTo=<%=Constants.PHOTO_PATH_ROOT_PARTNER %>&width=100&height=100";
            JS_LIB.popUpWindow(url, '#Photograph', 'Upload Hình');
            return false;
        });
    });
    var index = 1;
    function AddRow() {
        var rowCount = $('#tblAddress tr').length;
        index = rowCount - 1;
        index++;
        $("#hidValue").val(index);
        $("#tblAddress").append(
            "<tr><td style='width:150px'>" +
                   "<input maxlength='200' style='width: 200px' type='text' name='Street" + index + "' id='Street" + index + "'/>" +
                "</td>" +
                "<td style='width:150px'>" +
                    "<select style='width: 150px;' name='Province" + index + "' id='Province" + index + "' onchange = 'changeProvince(" + index + ")'></select>" +
                "</td>" +
                "<td style='width:150px'>" +
                    "<select style='width: 150px;' name='District" + index + "' id='District" + index + "'></select>" +
                "</td>" +
                 "<td style='width: 150px'>" +
                    "<input type='text' value='' style='width: 150px;' name='Phone" + index + "' maxlength='20' id='Phone" + index + "'>" +
                 "</td>" +
                "<td style='width: 50px;text-align:center'>" +
                       "<input type='radio' value='Address" + index + "' name='MainAddress' id='MainAddress'>" +
                 "</td>" +
                "</tr>");
        //$('#District1 option').clone().appendTo('#District' + index);
        $('#District' + index).append('<option value="">Chọn Quận/Huyện</option>');
        $('#Province1 option').clone().appendTo('#Province' + index);
        $("#Street" + index).rules("add", { required: true });
        $("#District" + index).rules("add", { required: true });
        $("#Province" + index).rules("add", { required: true });
    }
    function RemoveRow() {
        if (index > 1) {
            index--;
            $("#tblAddress tr:last").remove();
            $("#hidValue").val(index);
        }
    }
    //Dropdownlist 
    function changeProvince(index) {
        $("#District" + index).html("");
        var provinceId = $("#Province" + index).val();
        $("#District" + index).append($("<option value=''>Chọn Quận/Huyện</option>"));
        $.getJSON('/Library/GenericHandle/DropdownListHandler.ashx?ID=' + provinceId + '&Page=Province', function (item) {
            $.each(item, function () {
                if (this['ID'] != undefined) {
                    $("#District" + index).append($("<option value='" + this['ID'] + "'>" + this['Name'] + "</option>"));
                }
            });
        });
    }    
</script>
<table width="85%" border="0" cellpadding="0" cellspacing="0" class="edit">
    <tr>
        <td class="label">
            Hình Ảnh
        </td>
        <td class="input">
            <table>
                <tr>
                    <td>
                        <%
                            string labelPhoto = "<img src='/Content/Images/Common/nopic.gif' height='100px' width='100px' />";
                            if (ViewData.Model == null)
                            {
                                Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(partner.Logo) || (!string.IsNullOrEmpty(partner.Logo) && partner.Logo == Constants.NO_IMAGE))
                                {
                                    Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                                }
                                else
                                {
                                    labelPhoto = "<a id='thumb1' href='" + Constants.PHOTO_PATH_ROOT_PARTNER + partner.Logo
                                                    + "' class='highslide' onclick='return hs.expand(this)'>"
                                                    + "<img id='imgPhoto' src='" + Constants.PHOTO_PATH_ROOT_PARTNER + partner.Logo
                                                    + "' alt='Highslide JS' title='Nhấp vào để phóng to' height='100px' width='100px' /></a>";
                                    Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                                }
                            }
                            if (ViewData.Model == null)
                            {
                                Response.Write(Html.Hidden("RecordID", ""));
                                Response.Write(Html.Hidden("Photograph", ""));
                                Response.Write(Html.Hidden("hidValue", 1));
                            }
                            else
                            {
                                Response.Write(Html.Hidden("RecordID", partner.ID));
                                Response.Write(Html.Hidden("ID", partner.ID));
                                Response.Write(Html.Hidden("Photograph", partner.Logo));
                            }                            
                            Response.Write(Html.Hidden("LastOrder", ViewData["LastOrder"]));
                        %>
                    </td>
                    <td valign="top">
                        <input type="button" class="upload_image" id="btnChangePhoto" value="" title="Đổi Logo" />
                        <%  string stylePhoto = "display: none";
                            if (ViewData.Model != null)
                            {
                                if (!string.IsNullOrEmpty(partner.Logo) && partner.Logo != Constants.NO_IMAGE)
                                {
                                    stylePhoto = "display: block";
                                }
                            }
                        %>
                        <input type="button" id="btnRemoveImage" class="remove_image" style="<%=stylePhoto %>"
                            onclick="JS_LIB.msgConfirmBox('Bạn có chắc là bạn muốn xóa Logo?', 450,'JS_LIB.removeImageWithSize(\'<%=Constants.PARTNER_DEFAULT_VALUE %>\',100,100)','Xóa Logo');"
                            value="" title="Xóa Logo" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Tên Sản Phẩm <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("PartnerName", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("PartnerName", partner.PartnerName, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Chọn Danh Mục <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.DropDownList(CommonDataKey.CATEGORY, ViewData[CommonDataKey.CATEGORY] as SelectList, Constants.CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }
                else
                {
                    Response.Write(Html.DropDownList(CommonDataKey.CATEGORY, null, Constants.CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }                
            %>
        </td>
    </tr>
    <%--<tr>
        <td class="label required">
            Địa Chỉ <span>*</span>
        </td>
        <td class="input">
            <button type="button" onclick="AddRow();" class="icon plus">
            </button>
            <button type="button" onclick="RemoveRow();" class="icon minus">
            </button>
            <table id="tblAddress" border="0" cellpadding="0" cellspacing="0" width="400px" class="grid">
                <tr>
                    <th>
                        Địa Chỉ
                    </th>
                    <th>
                        Quận/Huyện
                    </th>
                    <th>
                        Tỉnh Thành
                    </th>
                    <th>
                        Điện Thoại
                    </th>
                    <th>
                        Trụ Sở Chính
                    </th>
                </tr>
                <%if (ViewData[CommonDataKey.ADDRESS] == null)
                  {  %>
                <tr>
                    <td style="width: 150px">
                        <input type="text" id='Street1' name="Street1" class="tempInvoiceDate text" maxlength="200"
                            style="width: 200px" />
                    </td>
                    <td style="width: 150px">
                        <%=Html.DropDownList("Province1", ViewData["Province1"] as SelectList, "Chọn Tỉnh Thành", new { @style = "width:150px", @onchange = "changeProvince(1)" })%>
                    </td>
                    <td style="width: 150px">
                        <%=Html.DropDownList("District1", null, "Chọn Quận/Huyện", new { @style = "width:150px" })%>
                    </td>
                    <td style="width: 150px">
                        <%=Html.TextBox("Phone1", string.Empty, new { @style = "width:150px", @maxlength = "20" })%>
                    </td>
                    <td style="width: 100px; text-align: center">
                        <%
                            Response.Write(Html.RadioButton("MainAddress", "Address1", true));                            
                        %>
                    </td>
                </tr>
                <% }
                  else
                  {
                      int index = 1;
                      List<PartnerAddress> listAddress = (List<PartnerAddress>)ViewData[CommonDataKey.ADDRESS];
                      Response.Write(Html.Hidden("hidValue", listAddress.Count));
                      foreach (PartnerAddress item in listAddress)
                      {
                %>
                <tr>
                    <td style="width: 150px">
                        <%=Html.TextBox("Street" + index, item.Address, new {@class="tempInvoiceDate text",
                        @maxlength="200",@style="width: 200px"}) %>
                    </td>
                    <td style="width: 150px">
                        <%=Html.DropDownList("Province" + index, new SelectList(proDao.GetList(), "ID", "ProvinceName", item.ProvinceID), "Chọn Tỉnh Thành", new { @style = "width:150px", @onchange = "changeProvince(" + index + ")" })%>
                    </td>
                    <td style="width: 150px">
                        <%=Html.DropDownList("District" + index, new SelectList(distDao.GetList(), "ID", "DistrictName", item.DistrictID), "Chọn Quận/Huyện", new { @style = "width:150px" })%>
                    </td>
                    <td style="width: 150px">
                        <%=Html.TextBox("Phone" + index, item.Phone, new { @style = "width:150px", @maxlength = "20" })%>
                    </td>
                    <td style="width: 100px; text-align: center">
                        <%
                            Response.Write(Html.RadioButton("MainAddress", "Address" + index, item.IsMainAddress));                            
                        %>
                    </td>
                </tr>
                <% index++;
                      }
                  }    
                %>
            </table>
        </td>
    </tr>--%>
    <tr>
        <td class="label required">
            Tình Trạng <span>*</span>
        </td>       
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Status", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Status", partner.Status, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Thời Gian Nhận
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("ReceivedTime", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("ReceivedTime", partner.ReceivedTime, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
        
    <tr>
        <td class="label">
            Giá cũ
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("OldPrice", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("OldPrice", partner.OldPrice, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Giá hiện tại
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("CurrentPrice", string.Empty, new { @maxlength = "20", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("CurrentPrice", partner.CurrentPrice, new { @maxlength = "20", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Giảm Giá
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("DiscountInfo", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("DiscountInfo", partner.DiscountInfo, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Hàng Có Sẵn
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.CheckBox("IsAvailable", false));
                }
                else
                {
                    Response.Write(Html.CheckBox("IsAvailable", partner.IsAvailable));
                }                
            %>
        </td>
    </tr>    
    <tr>
        <td class="label">
            Website
        </td>
        <td class="input">
            <%
                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Webiste", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Webiste", partner.Webiste, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Email
        </td>
        <td class="input">
            <%
                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Email", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Email", partner.Email, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Kho
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Store", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Store", partner.Store, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Ngày Hết Hạn
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.DatePicker("ExpireDate", DateTime.Now.AddYears(2).ToString(Constants.DATETIME_FORMAT), new { @maxlength = "10", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.DatePicker("ExpireDate", partner.ExpireDate.ToString(Constants.DATETIME_FORMAT), new { @maxlength = "10", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Mã số
        </td>
         <td class="input">
            <%
                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("CodeID", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("CodeID", partner.CodeID, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label" style="vertical-align: top">
            Giới Thiệu
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextArea("Description", string.Empty, new {@style = "width:600px;height:200px" }));
                }
                else
                {
                    Response.Write(Html.TextArea("Description", CommonFunc.SetHtmlForCKEditor(partner.Description), new { @style = "width:600px;height:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>        
        <td colspan="2" align="center">
            <input type="submit" class="save" value="" alt="" />
            <input type="button" class="cancel" value="" alt="" onclick="JS_LIB.redirect('/Administration/Partner/Index')" />
        </td>
    </tr>
</table>
